/****************************************************************************
**
**	File Name   : stdafx.h
**
**	Project     : DatChecker
**
**	Last Updated: $Header: /DatChecker.root/DatChecker/stdafx.h 11    2/27/04 8:56a Neusel $
**
**	Description : 
**
**		Include file for standard system include files, or project-specific 
**		definitions that are used frequently, but are changed infrequently.
**
****************************************************************************/
#ifndef	H_STDAFX
	#define H_STDAFX	__TIMESTAMP__

#if defined(_MSC_VER) && (_MSC_VER >= 1020)
#	pragma once
#endif
/*	----------------------------------------------------------------------
	Compiler Directives
	----------------------------------------------------------------------	*/
#define _WIN32_WINNT	0x0501
#define	_WIN32_IE		0x0500

#define _CRT_SECURE_NO_WARNINGS
#define	_WTL_USE_CSTRING

#include <atlbase.h>
#include <atlapp.h>

extern CAppModule _Module;

#include <atlwin.h>
#include <atlcoll.h>
#include <atlcrack.h>
#include <atlctrls.h>
#include <atlctrlx.h>
#include <atldlgs.h>
#include <atlfile.h>
#include <atlframe.h>
#include <atlmisc.h>

#include "atldib.h"
#include "atlgdix.h"

#include "MD5.h"
#include "ObjPalette.h"
/*	-----------------------------------------------------------------------
	Global Constants
	-----------------------------------------------------------------------	*/
const LPCTSTR			kStrEmpty		= _T("");

const LPCTSTR			kStrAppTitle	= _T("DatChecker");

#ifdef	_DEBUG
	const LPCTSTR		kStrVersion		= _T("v1.11 DEBUG");
#else
	const LPCTSTR		kStrVersion		= _T("v1.11");
#endif

const SIZE_T			kSV6ObjNameLen	= 8;
const SIZE_T			kStringLen		= 255;
const SIZE_T			kStrTableLen	= 511;

enum	WMU
			{
			WMU_BROWSE	= WM_USER + 1,
			WMU_END_SCAN
			};
/*	-----------------------------------------------------------------------
	Global Typedefs
	-----------------------------------------------------------------------	*/
typedef CAtlArray<BYTE>		XBuffer;

struct Options
	{
	bool			bCustomOnly,
					bGridLines,
					bVerify;
	int				nLanguage;
	COLORREF		clrTransparent;
	RECT			rMainDlg,
					rObjInfoDlg,
					rObjViewDlg;
	TCHAR			szObjDataPath[MAX_PATH+1];
	};
	
#pragma pack(push, 1)

struct SV6ObjGroup
	{
	DWORD		dwFlags;
	BYTE		xName[kSV6ObjNameLen];
	DWORD		dwCRC;
	};
	
struct SV6ObjImage
	{
	DWORD		dwStart;
	short		nWidth,
				nHeight,
				nXOffset,
				nYOffset;
	WORD		wFlags;
	WORD		wUnused;
	};

struct SV6ObjImageDir
	{
	DWORD		dwImageCount;
	DWORD		dwScanLines;
	SV6ObjImage	image[1];		// usually more than 1...
	};

typedef SV6ObjImageDir *	SV6ObjImageDirPtr;

struct SV6ObjHeader
	{
	DWORD			dwFlags;
	BYTE			xName[kSV6ObjNameLen];
	DWORD			dwCRC;
	BYTE			xCompression;
	DWORD			dwChunkSize;
	};

typedef SV6ObjHeader *	SV6ObjHeaderPtr;

#pragma pack(pop)

enum	ObjAuthor	{
					OA_UNKNOWN	= -1,
					OA_RCT2,
					OA_RCT2_WW,
					OA_RCT2_TT,
					OA_CUSTOM
					};

enum	ObjType		{
					OT_UNKNOWN = -1,
					OT_RIDE_SHOP,
					OT_SM_SCENERY,
					OT_LG_SCENERY,
					OT_WALLS,
					OT_BANNERS,
					OT_PATHS,
					OT_PATH_ITEMS,
					OT_GROUP,
					OT_ENTRANCE,
					OT_WATER,
					OT_SC6_TEXT
					};


#define	IS_RCT2(a)			((a) == OA_RCT2 || (a) == OA_RCT2_WW || (a) == OA_RCT2_TT)
#define	IS_VALID_OBJTYPE(n)	((n) >= OT_RIDE_SHOP && (n) <= OT_SC6_TEXT)

enum	FLAG_IMAGE_LIST
			{
			FLAG_RED,
			FLAG_YELLOW,
			FLAG_GREEN,
			FLAG_BOTH,
			FLAG_COUNT
			};

struct	ObjInfo		{
					int				nFlag;		// FLAG_* constant
					ObjAuthor		author;		// source of object
					ObjType			type;		// type of object
					DWORD			dwCRC;		// CRC
					MD5::Digest		digest;		// MD5 digest
					int				nImages;	// count of images
					SIZE_T			sDataLen;	// length of object data
					SIZE_T			sFileLen;	// length of object file
					SIZE_T			sImageDir;	// offset to image directory
					TCHAR			szFile[MAX_PATH+1];			// object file
					TCHAR			szInfo[kStringLen+1];		// "Details"
					TCHAR			szName[kSV6ObjNameLen+1];	// object name
					TCHAR			szStrings[kStrTableLen+1];	// string table
					};
					
typedef ObjInfo *	ObjInfoPtr;
/*	-----------------------------------------------------------------------
	Global Macros
	-----------------------------------------------------------------------	*/
#define	NOTHING			((void) 0)
/*
**	xB() -- helper macros to quickly and easier generate size constants.
*/
#define	KB(n)			(SIZE_T(n) << 10)
#define MB(n)			(SIZE_T(n) << 20)
#define	GB(n)			(SIZE_T(n) << 30)
/*
**	ARRAY_DIM() -- computes the number of elements in an array
*/
#define	ARRAY_DIM(x)	(sizeof(x)/sizeof((x)[0]))
/*
**	xxx_PTR()/xxx_HND() -- test pointers and handles for validity
*/
#define GOOD_PTR(p)		(NULL != PVOID(p))
#define NULL_PTR(p)		(NULL == PVOID(p))

#define	GOOD_HND(h)		(NULL != HANDLE(h) && INVALID_HANDLE_VALUE != HANDLE(h))
#define	NULL_HND(h)		(NULL == HANDLE(h) || INVALID_HANDLE_VALUE == HANDLE(h))
/*
**	PC-Lint helpers
*/
#define LINT_FREE_BEGIN	/*lint -save --e{*} */
#define LINT_FREE_END	/*lint -restore */
#define	LINT_IGNORE(n)	/*lint --e{n} */
#define	LINT_USED(x)	/*lint --esym(715,x) */
/*
**	MAKE_PTR(cast, ptr, count) simplifies ptr math by adding "number" to
**		the "ptr", and then casting the new value as a "cast".  For example,
**		MAKE_PTR(LPTSTR, pv, 5) is equivalent to (LPTSTR)&(((BYTE *)pv)[5])
*/
#define	MAKE_PTR(c,p,n)	reinterpret_cast<c>(SIZE_T(p)+SIZE_T(n))
#define OFFSET_OF(s,m)	((SIZE_T)&(((s *)0)->m))
/*
**	Error handling macros, all of which eventually resolve to a call to
**	the Panic() function.
*/
#define	PANIC(e)		Panic(DWORD(e), __FILE__, __LINE__)

#define	PANIC_IF(x,e)	 { if (x) PANIC(e); }
#define PANIC_IF_NULL(p) { if (NULL_PTR(p)) PANIC(ERROR_INVALID_DATA); }
/*
**	ROTx() macros rotate a given value left or right by a specified number of
**	bits.
*/
#define	ROTR32(x,y)		_rotr((x),(y))
#define ROTR8(x,y)		(((x)>>(y&7)) | ((x)<<(8-(y&7))))
/*	-----------------------------------------------------------------------
	Global Function Prototypes
	-----------------------------------------------------------------------	*/
/*
**	stdafx.cpp
*/
void					Panic(DWORD, LPCTSTR, UINT);
/*
**	SV6Object.cpp
*/
bool					CloneObject(ObjInfo const &, CString const &, const bool);
bool					ExamineObject(CAtlFile const &,	ObjInfo &);
bool					IsValidName(LPCTSTR);
int						LoadObjectImageData(ObjInfo const &, XBuffer &);
void					ScanObjectFolder(SIZE_T, HWND, LPCTSTR);
/*
**	Utility.cpp
*/
void					PlaceWindow(CWindow &, RECT const &);
LPTSTR					StrByteCount(LONG);
int						StrCmpPartial(LPCTSTR, LPCTSTR, const bool bCase = false);
LPTSTR					StrFileTime(FILETIME const &);
LPTSTR					StrNum(LONG);

#endif	// H_STDAFX
/****************************************************************************
**
**	$History: stdafx.h $
 * 
 * *****************  Version 11  *****************
 * User: Neusel       Date: 2/27/04    Time: 8:56a
 * Updated in $/DatChecker.root/DatChecker
 * v1.9 -- Added drag and drop handler.
 * 
 * *****************  Version 10  *****************
 * User: Neusel       Date: 1/21/04    Time: 6:40p
 * Updated in $/DatChecker.root/DatChecker
 * 
 * *****************  Version 9  *****************
 * User: Neusel       Date: 1/20/04    Time: 12:08p
 * Updated in $/DatChecker.root/DatChecker
 * v1.7 -- rearranged Properties dialog and added yellow flags.
 * 
 * *****************  Version 8  *****************
 * User: Neusel       Date: 1/15/04    Time: 12:45p
 * Updated in $/DatChecker.root/DatChecker
 * v1.6 -- improved command line parsing, better graphics scaling, add
 * "Copy to Clipboard" button.
 * 
 * *****************  Version 7  *****************
 * User: Neusel       Date: 1/02/04    Time: 12:37p
 * Updated in $/DatChecker.root/DatChecker
 * Modified decompress() to use dynamically allocated arrays.
 * CObjViewDlg now caches image data.
 * 
 * *****************  Version 6  *****************
 * User: Neusel       Date: 12/31/03   Time: 4:48p
 * Updated in $/DatChecker.root/DatChecker
 * v1.5 -- Added object image viewing.
 * 
 * *****************  Version 5  *****************
 * User: Neusel       Date: 12/17/03   Time: 8:58a
 * Updated in $/DatChecker.root/DatChecker
 * 
 * *****************  Version 4  *****************
 * User: Neusel       Date: 10/27/03   Time: 11:43a
 * Updated in $/DatChecker.root/DatChecker
 * v1.3 -- added "/verify" flag to make object data check optional.
 * 
 * *****************  Version 3  *****************
 * User: Neusel       Date: 9/08/03    Time: 9:34a
 * Updated in $/DatChecker.root/DatChecker
 * v1.2 -- added ObjData header file and internal checks.
 * 
 * *****************  Version 2  *****************
 * User: Neusel       Date: 8/14/03    Time: 3:59p
 * Updated in $/DatChecker.root/DatChecker
 * Added "Object Clone" and String Table capability.
 * 
 * *****************  Version 1  *****************
 * User: Neusel       Date: 8/14/03    Time: 9:25a
 * Created in $/DatChecker.root/DatChecker
**
**	-------------------------------------------------------------------------
**
**	End of stdafx.h
**
****************************************************************************/
